/*
 * AñadirEntregas.java
 *
 * Created on 13-feb-2012, 11:41:33
 */

package interfazgrafica.modificar.entregas;

import interfazgrafica.ayuda.VentanaAyuda;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Lauaa
 */
public class AñadirEntregas extends javax.swing.JFrame {
    private final Connection conn;
    private final Statement stmt;
    private String[] args;

    /** Creates new form AñadirEntregas */
    public AñadirEntregas(java.awt.Frame parent, boolean modal) throws ClassNotFoundException, SQLException {
        initComponents();
                //Accedo a la base de datos.
            Class.forName("oracle.jdbc.OracleDriver");
            conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "system", "terrano89");
            stmt = conn.createStatement();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jTextFieldCodigoTanque1 = new javax.swing.JTextField();
        jLabelcodigoTanque1 = new javax.swing.JLabel();
        jLabeCodigoTanque2 = new javax.swing.JLabel();
        jTextFieldCodigoTanque2 = new javax.swing.JTextField();
        jLabeMes = new javax.swing.JLabel();
        jTextFieldMuestras = new javax.swing.JTextField();
        jTextFieldCodigoCisterna = new javax.swing.JTextField();
        jTextFieldId = new javax.swing.JTextField();
        jLabelAño = new javax.swing.JLabel();
        jTextFieldAño = new javax.swing.JTextField();
        jTextFieldCIF = new javax.swing.JTextField();
        jTextFieldMes = new javax.swing.JTextField();
        jLabelId = new javax.swing.JLabel();
        jLabelFecha = new javax.swing.JLabel();
        jLabeCodigoCisterna = new javax.swing.JLabel();
        jLabelNumeroCIF = new javax.swing.JLabel();
        jTextFieldFecha = new javax.swing.JTextField();
        jLabelMuestras = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(cowmanager.CowManagerApp.class).getContext().getResourceMap(AñadirEntregas.class);
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jTextFieldCodigoTanque1.setName("jTextFieldCodigoTanque1"); // NOI18N

        jLabelcodigoTanque1.setText(resourceMap.getString("jLabelcodigoTanque1.text")); // NOI18N
        jLabelcodigoTanque1.setName("jLabelcodigoTanque1"); // NOI18N

        jLabeCodigoTanque2.setText(resourceMap.getString("jLabeCodigoTanque2.text")); // NOI18N
        jLabeCodigoTanque2.setName("jLabeCodigoTanque2"); // NOI18N

        jTextFieldCodigoTanque2.setName("jTextFieldCodigoTanque2"); // NOI18N

        jLabeMes.setText(resourceMap.getString("jLabeMes.text")); // NOI18N
        jLabeMes.setName("jLabeMes"); // NOI18N

        jTextFieldMuestras.setName("jTextFieldMuestras"); // NOI18N

        jTextFieldCodigoCisterna.setName("jTextFieldCodigoCisterna"); // NOI18N

        jTextFieldId.setName("jTextFieldId"); // NOI18N

        jLabelAño.setText(resourceMap.getString("jLabelAño.text")); // NOI18N
        jLabelAño.setName("jLabelAño"); // NOI18N

        jTextFieldAño.setName("jTextFieldAño"); // NOI18N

        jTextFieldCIF.setName("jTextFieldCIF"); // NOI18N

        jTextFieldMes.setName("jTextFieldMes"); // NOI18N

        jLabelId.setText(resourceMap.getString("jLabelId.text")); // NOI18N
        jLabelId.setName("jLabelId"); // NOI18N

        jLabelFecha.setText(resourceMap.getString("jLabelFecha.text")); // NOI18N
        jLabelFecha.setName("jLabelFecha"); // NOI18N

        jLabeCodigoCisterna.setText(resourceMap.getString("jLabeCodigoCisterna.text")); // NOI18N
        jLabeCodigoCisterna.setName("jLabeCodigoCisterna"); // NOI18N

        jLabelNumeroCIF.setText(resourceMap.getString("jLabelNumeroCIF.text")); // NOI18N
        jLabelNumeroCIF.setName("jLabelNumeroCIF"); // NOI18N

        jTextFieldFecha.setName("jTextFieldFecha"); // NOI18N

        jLabelMuestras.setText(resourceMap.getString("jLabelMuestras.text")); // NOI18N
        jLabelMuestras.setName("jLabelMuestras"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(40, 40, 40)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 342, Short.MAX_VALUE)
                        .addComponent(jButton3)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabelcodigoTanque1)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldCodigoTanque1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabelMuestras)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jTextFieldMuestras, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabelFecha)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabelId)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabeMes)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldMes, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                                .addComponent(jLabelAño)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldAño, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabeCodigoCisterna)
                                    .addComponent(jLabelNumeroCIF))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jTextFieldCodigoCisterna, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                                    .addComponent(jTextFieldCIF, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabeCodigoTanque2)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldCodigoTanque2, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)))
                        .addGap(73, 73, 73))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldCodigoCisterna, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabeCodigoCisterna))
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldCIF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelFecha)
                            .addComponent(jTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextFieldMuestras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabelNumeroCIF))
                            .addComponent(jLabelMuestras))))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelId)
                        .addComponent(jTextFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabeMes)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldAño, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelAño)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelcodigoTanque1)
                    .addComponent(jTextFieldCodigoTanque1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabeCodigoTanque2)
                    .addComponent(jTextFieldCodigoTanque2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(51, 51, 51)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String consulta = "INSERT INTO entregas VALUES (";
        consulta = consulta + "'" + jTextFieldId.getText() +"', ";
        consulta = consulta + "'" + jTextFieldMes.getText() +"', ";
        consulta = consulta + "'" + jTextFieldAño.getText() +"', ";
        consulta = consulta + "'" + jTextFieldFecha.getText() +"', ";
        consulta = consulta + "'" + jTextFieldCodigoTanque1.getText() +"', ";
        consulta = consulta + "'" + jTextFieldCodigoTanque2.getText() +"', ";
        consulta = consulta + "'" + jTextFieldCIF.getText() +"', ";
        consulta = consulta + "'" + jTextFieldCodigoCisterna.getText() +"', ";
        consulta = consulta + "'" + jTextFieldMuestras.getText() +"')";
        System.out.println(consulta);
        //Hago una consulta y la guardo en rs.
        ResultSet rs = null;
        try {
            rs = stmt.executeQuery(consulta);
        } catch (SQLException ex) {
            Logger.getLogger(AñadirEntregas.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            rs.close();
        } catch (SQLException ex) {
            Logger.getLogger(AñadirEntregas.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            stmt.close();
        } catch (SQLException ex) {
            Logger.getLogger(AñadirEntregas.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(AñadirEntregas.class.getName()).log(Level.SEVERE, null, ex);
        }
        ModificarEntregas.main(args);
        this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        ModificarEntregas.main(args);
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        VentanaAyuda ayuda = new VentanaAyuda("Modificar entregas");
        ayuda.setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(final String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    AñadirEntregas dialog = new AñadirEntregas(new javax.swing.JFrame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                        public void windowClosing(java.awt.event.WindowEvent e) {
                            ModificarEntregas.main(args);
                        }
                    });
                    dialog.setVisible(true);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(AñadirEntregas.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(AñadirEntregas.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabeCodigoCisterna;
    private javax.swing.JLabel jLabeCodigoTanque2;
    private javax.swing.JLabel jLabeMes;
    private javax.swing.JLabel jLabelAño;
    private javax.swing.JLabel jLabelFecha;
    private javax.swing.JLabel jLabelId;
    private javax.swing.JLabel jLabelMuestras;
    private javax.swing.JLabel jLabelNumeroCIF;
    private javax.swing.JLabel jLabelcodigoTanque1;
    private javax.swing.JTextField jTextFieldAño;
    private javax.swing.JTextField jTextFieldCIF;
    private javax.swing.JTextField jTextFieldCodigoCisterna;
    private javax.swing.JTextField jTextFieldCodigoTanque1;
    private javax.swing.JTextField jTextFieldCodigoTanque2;
    private javax.swing.JTextField jTextFieldFecha;
    private javax.swing.JTextField jTextFieldId;
    private javax.swing.JTextField jTextFieldMes;
    private javax.swing.JTextField jTextFieldMuestras;
    // End of variables declaration//GEN-END:variables

}
